package com.fileLoader.pojo;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.FileReader;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import com.fileLoader.pojo.mongo.FilePositionSetting;
import com.fileLoader.pojo.mongo.MoveFile;


public class Loadfile {
	public static void main(String[] args) {
		
		
		
		String fileDir = "/Users/libin/Documents/workspace-sts-3.9.0.RELEASE/fileLoader/data/logs/scan";
		final String baseFileName = "scan";
		final String handelUUID = "";
		MoveFile moveFile = new MoveFile();//需要移动的文件
		
		File mainFile = new File(fileDir);//主目录
		File[] secondFiles = mainFile.listFiles();//二级目录--主目录下的文件夹
		File[] handleFiles = new File[] {};//二级目录下的各个文件
		for(File file2 : secondFiles) {
			if (file2.isDirectory()) {//只遍历二级文件夹
				if (file2.listFiles().length != 0) {
					handleFiles = file2.listFiles(new FileFilter() {//二级目录下的各个文件
						public boolean accept(File pathname) {
							if (pathname.getName().indexOf(baseFileName)!= -1) {
								return true;
							}
							return false;
						}
					});
					if (handleFiles.length != 0) {
						break;
					}
				}
			}
		}
		
		if (handleFiles != null) {//需要处理的文件
			for(File onhandFile : handleFiles) {
				System.out.println(onhandFile.getPath());
				try {
					FileReader fileReader = new FileReader(onhandFile);
					BufferedReader bufferedReader = new BufferedReader(fileReader);
					String data = bufferedReader.readLine();
					if (StringUtils.isNotBlank(data)) {
						String[] dataArray = data.split("-");
						String UUID = dataArray[0];
						if (UUID.equals(handelUUID)) {
							String handleData = dataArray[1];
						}
						
					}
				} catch (Exception e) {
					// TODO: handle exception
				}
			}
		}
		
	}
}
